package com.yz.lzq.liwushuo.ui.modules.home.boutique.gridview.christmas;

import com.yz.lzq.liwushuo.http.HttpUtils;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.christmas.ChristmasBean;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/12/21.
 */

public class ChristmasModel implements ChristmasContract.ChristmasModelInterface {
    @Override
    public void getNetWorkData(int limit, int offset, String urlId, final OnGetNetDataListener<ChristmasBean> listener, boolean loadMore) {
/**
 * get请求 请求通过@queryMap注解动态的传递多个参数
 */
        //gender=1&generation=2
        Map<String, String> map = new HashMap<>();
        map.put("limit", limit + "");
        map.put("offset", offset + "");
        Observable<ChristmasBean> observable = HttpUtils.getInstance().getIApi().getChristmasRecycleBean("collections/" + urlId + "/posts", map);
        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ChristmasBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.onGetDataFalied(e);
                    }

                    @Override
                    public void onNext(ChristmasBean christmasBean) {
                        listener.onGetDataSucess(christmasBean);
                    }
                });

    }

}

